import QtQuick

import QtQuick.Layouts
import qc.window 1.0
Rectangle{
    id:titleBar
    property var thisTheme: p_theme.defaultTheme[p_theme.current]
    width: parent.width
    height: 80
    color:thisTheme.backgroundColor
    MouseArea{
        property var click_pos: Qt.point(0,0)
        anchors.fill: parent
        onPositionChanged: function(mouse){
            if(!pressed)return
            if(!window.startSystemMove()){
                var offset=Qt.point(mouseX-click_pos.x,mouseY-click_pos.y)
                window.x+=offset.x
                window.y+=offset.y

            }
        }
        onPressedChanged: function(mouse){
            click_pos=Qt.point(mouseX,mouseY)
        }
        onDoubleClicked: {
            if(window.visibility===Window.Maximized){
                window.showNormal()
            }else{
                window.showMaximized()
            }
        }
        RowLayout{
            width: parent.width-20
            height: parent.height-10
            anchors.centerIn: parent
            Row{
                width: 80
                height: parent.height
                spacing:15
                Image{
                    width:40
                    height:width
                    anchors.verticalCenter: parent.verticalCenter
                    source: "qrc:/Images/wind.png"
                }
                Text{
                    font.pointSize: 12
                    anchors.verticalCenter: parent.verticalCenter
                    text:"Hotel Manage System"
                    color:thisTheme.fontColor
                }
                Component.onCompleted: {
                    width=children[0].width+children[1].contentWidth+parent.spacing
                }
            }
            Item{Layout.preferredWidth: 10;Layout.fillWidth:true}
            Row{
                width: 30*3+5*3
                spacing: 5
                Rectangle{
                    id:minWindowBtn
                    property bool isHoverd:false
                    width: 30
                    height:width
                    radius: 100
                    color:if(isHoverd) return "#1F572920"
                            else return "#00000000"
                    Rectangle{
                        width:parent.width-5
                        height: 3
                        anchors.centerIn: parent
                        border.width: 2
                        border.color: thisTheme.fontColor
                        color:"#00000000"
                    }

                    MouseArea{
                        anchors.fill: parent
                        hoverEnabled: true
                        onClicked: {
                            window.showMinimized()
                        }
                        onEntered: {
                            parent.isHoverd=true
                        }
                        onExited: {
                            parent.isHoverd=false
                        }
                    }
                }
                Rectangle{
                    id:minMaxWindowBtn
                    property bool isHoverd:false
                    width: 30
                    height:width
                    radius: 100
                    color:if(isHoverd) return "#1F572920"
                            else return "#00000000"
                    Rectangle{
                        width:parent.width-5
                        height: width
                        anchors.centerIn: parent
                        radius: 100
                        color:"#00000000"
                        border.width: 2
                        border.color: thisTheme.fontColor
                    }

                    MouseArea{
                        anchors.fill: parent
                        hoverEnabled: true
                        onClicked: {
                            if(window.visibility==Window.Maximized){
                                window.showNormal()
                            }else{
                                window.showMaximized()
                            }
                        }
                        onEntered: {
                            parent.isHoverd=true
                        }
                        onExited: {
                            parent.isHoverd=false
                        }
                    }
                }
                Rectangle{
                    id:quitWindowBtn
                    property bool isHoverd:false
                    width: 30
                    height:width
                    radius: 100
                    color:if(isHoverd) return "#1F572920"
                            else return "#00000000"
                    Rectangle{
                        width:parent.width-10
                        height:3
                        border.color: thisTheme.fontColor
                        anchors.centerIn: parent
                        rotation: 45
                        color:thisTheme.fontColor
                    }
                    Rectangle{
                        width:parent.width-5
                        height:3
                        border.color: thisTheme.fontColor
                        anchors.centerIn: parent
                        rotation: -45
                        color:thisTheme.fontColor
                    }
                    MouseArea{
                        anchors.fill: parent
                        hoverEnabled: true
                        onClicked: {
                            Qt.quit()
                        }
                        onEntered: {
                            parent.isHoverd=true
                        }
                        onExited: {
                            parent.isHoverd=false
                        }
                    }
                }
            }
        }

    }
}

